package sg.edu.nus.ivletalk.test;

import java.util.ArrayList;

import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.SpeechRecognizer;
import android.widget.EditText;

public class RecognitionListenerImpl implements RecognitionListener {
	private EditText text;

	public RecognitionListenerImpl(EditText text) {
		this.text = text;
	}

	@Override
	public void onBeginningOfSpeech() {
		// do nothing

	}

	@Override
	public void onBufferReceived(byte[] arg0) {
		// do nothing

	}

	@Override
	public void onEndOfSpeech() {
		text.append("End of Speech");

	}

	@Override
	public void onError(int arg0) {
		text.setText("ERROR!! "+arg0);

	}

	@Override
	public void onEvent(int arg0, Bundle arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPartialResults(Bundle arg0) {
		String[] arr = arg0
				.getStringArray(SpeechRecognizer.RESULTS_RECOGNITION);
		text.setText("");
		for (String s : arr) {
			text.append(s+"\n");		
		}
	}

	@Override
	public void onReadyForSpeech(Bundle arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onResults(Bundle arg0) {
		ArrayList<String> arr = arg0
				.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
		text.setText("");
		for (String s : arr) {
			text.append(s+"\n");
		}

	}

	@Override
	public void onRmsChanged(float arg0) {
		// TODO Auto-generated method stub

	}

}
